/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canteen.sys.model.entity.repository;

import canteen.sys.model.entity.ItemMaster;
import canteen.sys.model.generic.GenericHibernateDAOSupport;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author TNT
 */
public class ItemMasterDAOImpl extends GenericHibernateDAOSupport<ItemMaster, Long> implements ItemMasterDAO {

    @Override
    public List<ItemMaster> findAllByStatus(boolean status) {
        Transaction transaction = getSession().beginTransaction();
        //sao giong cai login cua minh the nhi :)) no con ko the nhan dc tham so nua co! chua kip truyen vao gi bao null pointer
        //mac du tham so la co gia tri
        //findAll co roi viet lai lam gi
        //...k biet nua ro rang la nguyen code cua cai itemtype sang item thoi co' sua? gi dau
        //thi vay nhung toi con ko hieu tai sao no null! mac du ro rang la no dung!.k
        List<ItemMaster> listDepartment = getSession().createCriteria(ItemMaster.class)
                .add(Restrictions.eq("status", status)).list();
        transaction.commit();
        return listDepartment;
    }

    @Override
    public List<ItemMaster> findAllByItemTypeIdAndStatus(int typeId, boolean status) {
        Transaction transaction = getSession().beginTransaction();
        //sao giong cai login cua minh the nhi :)) no con ko the nhan dc tham so nua co! chua kip truyen vao gi bao null pointer
        //mac du tham so la co gia tri
        //findAll co roi viet lai lam gi
        //...k biet nua ro rang la nguyen code cua cai itemtype sang item thoi co' sua? gi dau
        //thi vay nhung toi con ko hieu tai sao no null! mac du ro rang la no dung!.k
        List<ItemMaster> listDepartment = getSession().createCriteria(ItemMaster.class)
                .add(Restrictions.eq("status", status))
                .add(Restrictions.eq("itemType.itemTypeId", typeId)).list();
        transaction.commit();
        return listDepartment;
    }

    @Override
    public ItemMaster findById(int id) {
        ItemMaster im = null;
        try {
            Transaction transaction = getSession().beginTransaction();
            im = (ItemMaster) getSession().get(ItemMaster.class, id);
            transaction.commit();
        } catch (HibernateException ex) {
        }
        return im;
    }
}
